//
//  WebHandler.h
//  Phidgets
//
//  Created by Daniel Hazelbaker on 12/28/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//


#include "mongcpp.h"
#include "Utils.h"


#ifndef Phidgets_WebHandler_h
#define Phidgets_WebHandler_h

class WebServer;

void RegisterWebHandlers(WebServer &server);

//
// The data that will be passed to web handlers.
//
class WebHandlerData
{
public:
    mongoose::MongooseConnection &connection;
    const mongoose::MongooseRequest &request;
    mongoose::MongooseResponse &response;
    WebHandlerData(mongoose::MongooseConnection &conn, const mongoose::MongooseRequest &req, mongoose::MongooseResponse &resp) : connection(conn), request(req), response(resp) { }
};

//
// The method definition for the web server handler.
//
typedef void (*WebServerHandler)(WebHandlerData &data, const StringDictionary &parameters);

//
// Define the information about a web handler.
//
class WebHandler
{
public:
    std::string method;
    std::string uri;
    WebServerHandler handler;
    
    WebHandler() : method(""), uri(""), handler(NULL) { }
    WebHandler(std::string m, std::string u, WebServerHandler h) : method(m), uri(u), handler(h) { }
};

#endif
